// pages/shezhi/fiveSection/fiveSection.js


const app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {

        // xlbfb: ['心率储存百分比(推荐)', '最大心率百分比'],
        // xlbfbIndex: 0,

        hrb: {
            rest_heart: 0,
            max_heart: 0,
            d5: 0,
            d6: 0,
            d7: 0,
            d8: 0,
            d9: 0,
        }


    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this
        that.setData({
            hrb: app.globalData.hrb
        })

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    saveHR: function (e) {
        console.log(e)
        let newValue = e.target.dataset.input
        console.log(newValue)
    },
    formSubmit: function (e) {
        console.log('====>>e')
        let values = e.detail.value
        let d5 = values.ecg_d5
        let d6 = values.ecg_d6
        let d7 = values.ecg_d7
        let d8 = values.ecg_d8
        let d9 = values.ecg_d9
        if (d5 <= app.globalData.hrb.rest_heart) {
            d5 = parseInt(app.globalData.hrb.rest_heart) + 1
        }
        if (d5 >= app.globalData.hrb.d6) {
            d5 = parseInt(app.globalData.hrb.d6) - 1
        }
        // app.globalData.hrb.d5 = d5

        if (d6 <= app.globalData.hrb.d5) {
            d6 = parseInt(app.globalData.hrb.d5) + 1
        }
        if (d6 >= app.globalData.hrb.d7) {
            d6 = parseInt(app.globalData.hrb.d7) - 1
        }
        // app.globalData.hrb.d6 = d6

        if (d7 <= app.globalData.hrb.d6) {
            d7 = parseInt(app.globalData.hrb.d6) + 1
        }
        if (d7 >= app.globalData.hrb.d8) {
            d7 = parseInt(app.globalData.hrb.d8) - 1
        }
        // app.globalData.hrb.d7 = d7


        if (d8 <= app.globalData.hrb.d7) {
            d8 = parseInt(app.globalData.hrb.d7) + 1
        }
        if (d8 >= app.globalData.hrb.d9) {
            d8 = parseInt(app.globalData.hrb.d9) - 1
        }
        // app.globalData.hrb.d8 = d8

        if (d9 <= app.globalData.hrb.d8) {
            d9 = parseInt(app.globalData.hrb.d8) + 1
        }
        if (d9 >= app.globalData.hrb.max_heart) {
            d9 = parseInt(app.globalData.hrb.max_heart) - 1
        }
        // app.globalData.hrb.d9 = d9


        console.log(d5)
        console.log(d6)
        console.log(d7)
        console.log(d8)
        console.log(d9)
        let hrb = {
            rest_heart: 0,
            max_heart: 0,
            d5: d5,
            d6: d6,
            d7: d7,
            d8: d8,
            d9: d9,
        }

        utilH.setStorage('hrb',hrb,function (res) {

        })
        wx.navigateBack({
            delta: 1
        })

    },
    // bindPickerChangeBfb: function (e) {
    //   var that = this
    //   console.log('picker发送选择改变，携带值为', e.detail.value)
    //   console.log(that.data.xlbfb[e.detail.value])
    //   that.setData({
    //     xlbfbIndex: e.detail.value
    //   })
    // },
    countdv5: function (e) {
        let d5 = e.detail.value
        if (d5 <= app.globalData.hrb.rest_heart) {
            d5 = parseInt(app.globalData.hrb.rest_heart) + 1
        }
        if (d5 >= app.globalData.hrb.d6) {
            d5 = parseInt(app.globalData.hrb.d6) - 1
        }
        app.globalData.hrb.d5 = d5
        this.onShow()
    },
    countdv6: function (e) {
        let d6 = e.detail.value
        if (d6 <= app.globalData.hrb.d5) {
            d6 = parseInt(app.globalData.hrb.d5) + 1
        }
        if (d6 >= app.globalData.hrb.d7) {
            d6 = parseInt(app.globalData.hrb.d7) - 1
        }
        app.globalData.hrb.d6 = d6
        this.onShow()
    },
    countdv7: function (e) {
        let d7 = e.detail.value
        if (d7 <= app.globalData.hrb.d6) {
            d7 = parseInt(app.globalData.hrb.d6) + 1
        }
        if (d7 >= app.globalData.hrb.d8) {
            d7 = parseInt(app.globalData.hrb.d8) - 1
        }
        app.globalData.hrb.d7 = d7
        this.onShow()
    },
    countdv8: function (e) {
        let d8 = e.detail.value
        if (d8 <= app.globalData.hrb.d7) {
            d8 = parseInt(app.globalData.hrb.d7) + 1
        }
        if (d8 >= app.globalData.hrb.d9) {
            d8 = parseInt(app.globalData.hrb.d9) - 1
        }
        app.globalData.hrb.d8 = d8
        this.onShow()
    },
    countdv9: function (e) {
        let d9 = e.detail.value
        if (d9 <= app.globalData.hrb.d8) {
            d9 = parseInt(app.globalData.hrb.d8) + 1
        }
        if (d9 >= app.globalData.hrb.max_heart) {
            d9 = parseInt(app.globalData.hrb.max_heart) - 1
        }
        app.globalData.hrb.d9 = d9
        this.onShow()
    },
})
